package org.asiainfo.common.core.exception.file;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.asiainfo.common.core.exception.base.BaseException;

import java.io.Serial;
import java.util.Arrays;

/**
 * 文件格式不正确
 *
 * @author dotor-ww
 */
@NoArgsConstructor
@Data
@EqualsAndHashCode(callSuper = true)
public class InvalidExtensionException extends BaseException {

    @Serial
    private static final long serialVersionUID = 1L;

    private String[] allowedExtension;

    private String extension;

    private String filename;

    public InvalidExtensionException(String[] allowedExtension, String extension, String filename) {
        super("文件[" + filename + "]后缀[" + extension + "]不正确，请上传" + Arrays.toString(allowedExtension) + "格式");
        this.allowedExtension = allowedExtension;
        this.extension = extension;
        this.filename = filename;
    }

    /**
     * 图像类型异常
     */
    public static class InvalidImageExtensionException extends InvalidExtensionException {

        @Serial
        private static final long serialVersionUID = 1L;

        public InvalidImageExtensionException(String[] allowedExtension, String extension, String filename) {
            super(allowedExtension, extension, filename);
        }
    }

    /**
     * Flash类型异常
     */
    public static class InvalidFlashExtensionException extends InvalidExtensionException {

        @Serial
        private static final long serialVersionUID = 1L;

        public InvalidFlashExtensionException(String[] allowedExtension, String extension, String filename) {
            super(allowedExtension, extension, filename);
        }
    }

    /**
     * 媒体类型异常
     */
    public static class InvalidMediaExtensionException extends InvalidExtensionException {

        @Serial
        private static final long serialVersionUID = 1L;

        public InvalidMediaExtensionException(String[] allowedExtension, String extension, String filename) {
            super(allowedExtension, extension, filename);
        }
    }

    /**
     * 视频类型异常
     */
    public static class InvalidVideoExtensionException extends InvalidExtensionException {

        @Serial
        private static final long serialVersionUID = 1L;

        public InvalidVideoExtensionException(String[] allowedExtension, String extension, String filename) {
            super(allowedExtension, extension, filename);
        }
    }
}
